# Maintainer: Caleb Maclennan <caleb@alerque.com>
# Maintainer: T.J. Townsend <blakkheim@archlinux.org>
# Contributor: Dave Reisner <dreisner@archlinux.org>

pkgname=nawk
pkgver=20231124
_commit=fbd1d5b712e27a9bb527e39ed6e9bf3b9afbb1df # master
pkgrel=1
pkgdesc='The one, true implementation of AWK'
url="https://github.com/onetrueawk/awk"
license=(custom)
arch=(loong64 x86_64)
options=(!makeflags)
depends=(glibc)
makedepends=(git)
source=("git+https://github.com/onetrueawk/awk.git#commit=${_commit}"
        'manpage-naming.patch')
sha256sums=('SKIP'
            'fa1bade363896033a50fbdadc8fa2f490f85a044d11afcd537f317067c70d3b5')

pkgver() {
  grep "version " awk/main.c | sed -e 's/[^"]*"\([^"]*\)".*/\1/' -e 's/^\w*\ *//'
}

prepare() {
  cd awk
  patch -Np1 < "../${source[1]}"
}

check() {
  cd awk
  ./REGRESS
}

build() {
  cd awk
  # the final linking step doesn't honor LDFLAGS, so let's just throw it all
  # together into CFLAGS.
  make \
    "CPPFLAGS=-DHAS_ISBLANK $CPPFLAGS" \
    "CFLAGS=$CFLAGS $LDFLAGS"
}

package() {
  cd awk
  install -Dm0755 a.out "$pkgdir/usr/bin/$pkgname"
  install -Dm0644 awk.1 "$pkgdir/usr/share/man/man1/$pkgname.1"
  install -Dm0644 -t "$pkgdir/usr/share/licenses/$pkgname/" LICENSE
}
